package com.xiaoq.system.endpoint;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiaoq.coms.GenericDataResponse;
import com.xiaoq.coms.GenericResponse;
import com.xiaoq.system.entity.FeedbackEntity;
import com.xiaoq.system.entity.TermVerEntity;
import com.xiaoq.system.service.ITermVerService;
import com.xiaoq.system.vo.TermVerVo;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@RestController
@RequestMapping(value="/api/v1/termver")
public class TermVerEndpoint {
	
	@Autowired
	private ITermVerService terVer;
	
	private class TermVerDataResponse extends GenericDataResponse<TermVerVo>{}
	
	private static final Logger LOG = LoggerFactory.getLogger(TermVerEndpoint.class);
	
	@ApiOperation(value = "返回最新版本号相关信息", notes = "返回最新版本号相关信息")
	@ApiResponses({ @ApiResponse(code = 200, response = TermVerDataResponse.class, message = "返回最新版本号相关信息") })
	@GetMapping(value = "", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
	public ResponseEntity<?> getTerVer(@RequestParam(value="termType",required=true)@ApiParam(value="ANDROID或IOS",required=true)String termType){
		LOG.info("termType类型："+termType);
		if(StringUtils.isNotEmpty(termType)){
			TermVerEntity termVer = terVer.getNewTerVer(termType);
			TermVerVo termVerVo = null;
			if(termVer!=null){
				termVerVo = new TermVerVo();
				BeanUtils.copyProperties(termVer, termVerVo);
				return TermVerDataResponse.okWithData(termVerVo);
				
				
			}else{
				return GenericResponse.ng("没有查询到指定终端类型的版本号！");
			}
			
		}else{
			return GenericResponse.ng("请传递准确的终端类型！");
		}
	}
	

}
